package com.mc.music_web.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mc.music_web.entity.Song;
import com.mc.music_web.mapper.SongVoMapper;
import com.mc.music_web.services.SongVoService;
import com.mc.music_web.vo.SongVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class SongVoServiceImpl implements SongVoService {
    @Autowired
    private SongVoMapper songVoMapper;
    public List<SongVo> selectSongVo() {
        return songVoMapper.selectSongVo();
    }

    public Song selectBySong(Integer songId) {
        return songVoMapper.selectBySong(songId);
    }

    public int deleteSong(Integer songId) {
        return songVoMapper.deleteSong(songId);
    }

    public int insertSong(Song song) {
        return songVoMapper.insertSong(song);
    }

    public int updateSong(Song song) {
        return songVoMapper.updateSong(song);
    }



    /**
     * 分页查询
     * @param pageNum
     * @return
     */
   public PageInfo selectSongLimit(int pageNum){
       PageHelper.startPage(pageNum,2);
       List<SongVo> lists = songVoMapper.selectSongVo();
       PageInfo<SongVo> pageInfoSo = new PageInfo<SongVo>(lists);
       System.out.println("当前页码："+pageInfoSo.getPageNum());
       System.out.println("页面大小："+pageInfoSo.getPageSize());
       System.out.println("总记录数："+pageInfoSo.getTotal());
       System.out.println("是否有上一页："+pageInfoSo.isHasPreviousPage());
       System.out.println("是否有下一页："+pageInfoSo.isHasNextPage());
       System.out.println("总页面数："+pageInfoSo.getPages());
       return pageInfoSo;
    }

    public List<SongVo> selectByChooseSong(String keyword) {
        return songVoMapper.selectByChooseSong(keyword);
    }
}
